#!/usr/bin/perl -w
package clreqd_modules;

use strict;

sub append_to_file {
my %ARGS=@_;
my $f=$ARGS{FILE};
my $m=$ARGS{MSG};

	my $fd;
	if(! -e $f) {
		return "ERROR File '$f' does not exist.";
	}
	if(! -f $f) {
		return "ERROR File system object '$f' exists, but is not a file.";
	}
	open($fd,">>$f") or return "ERROR Can not open file '$f' to append to: $!";
	if($m =~ /^HH:/) {
		$m=pack("h*",substr($m,3));
	}
	chomp $m;
	if(! print $fd "$m\n") {
		close($fd);
		return "ERROR Unable to complete write of message to file '$f' : $!";
	}
	close($fd);
	return "OK";
}

1;
